/**
 * 
 */
package com.me.brainlessbirds.actors.skills;

import java.util.ArrayList;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Timer.Task;
import com.me.brainlessbirds.actors.GameObject;

/**
 * @author Maxens
 *         Skill is something swith an effect and a cooldown
 */
public abstract class Skill
{

	protected float					cooldown			= 0f;
	protected float					animationDuration	= 0f;
	//0 means it happens ones
	protected float					effectDuration		= 0f;
	protected Task					effectTaskInit		= null;
	protected Task					effectTaskUpdate	= null;
	protected Task					effectTaskEnd		= null;

	protected ArrayList<GameObject>	targets				= new ArrayList<GameObject>();
	protected float					damages				= 0f;

	/*
	 * TimeLeft before skill is available, if 0 skill is launchable
	 */
	private float					TimeLeft;

	public Skill(float _damages, float _cd)
	{
		animationDuration = 0.5f; // pareil comme on a pas d'animation on va pas mettre trop eleve, vaut mieux toucher aux cooldowns
		this.cooldown = _cd;
		this.damages = _damages;
		this.TimeLeft = 0f;
	}

	public void setTargets(ArrayList<GameObject> targetsArrayList)
	{
		this.targets = targetsArrayList;
	}

	//inflict damages to targets
	public void inflictDamage()
	{

		for (GameObject tar : this.targets)
		{
			if (tar != null)
				tar.takeDamage(damages);
		}
	}

	public boolean launchEffect(ArrayList<GameObject> targetsArrayList)
	{
		if (this.TimeLeft <= 0f)
		{
			this.setTargets(targetsArrayList);
			this.inflictDamage();
			this.effectTaskInit.run();
			this.TimeLeft = cooldown;
			return true;
		}
		return false;
	}

	public void updateCooldown()
	{
		if (this.TimeLeft > 0f)
		{
			this.TimeLeft -= Gdx.graphics.getDeltaTime();
		}
		else
		{
			//skill ready
		}
	}
}
